home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog6.arj / GINPUT2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  2.2 KB  |  96 lines

  1. { ginput2.pas -- Get input via TInputDialog (modified version) }
  2.  
  3. program Ginput;
  4.  
  5. {$R ginput.res}
  6.  
  7. uses WinTypes, WinProcs, WObjects, StdDlgs;
  8.  
  9. const
  10.  
  11.   id_Menu = 100;    { Menu resource ID }
  12.   cm_Prompt = 101;  { Prompt command ID }
  13.  
  14. type
  15.  
  16.   PCustom = ^TCustom;
  17.   TCustom = object(TInputDialog)
  18.     function CanClose: Boolean; virtual;
  19.   end;
  20.  
  21.   GinputApplication = object(TApplication)
  22.     procedure InitMainWindow; virtual;
  23.   end;
  24.  
  25.   PGinputWindow = ^GinputWindow;
  26.   GinputWindow = object(TWindow)
  27.     Buffer: array[0 .. 64] of Char;
  28.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  29.     procedure GetInput(var Msg: TMessage);
  30.       virtual cm_First + cm_Prompt;
  31.   end;
  32.  
  33.  
  34. { TCustom }
  35.  
  36. function TCustom.CanClose: Boolean;
  37. var
  38.   OkToClose: Boolean;
  39. begin
  40.   OkToClose := TInputDialog.CanClose;
  41.   if OkToClose then
  42.     OkToClose := Upcase(Buffer[0]) = 'Y';
  43.   if not OkToClose then
  44.   begin
  45.     MessageBeep(0);
  46.     MessageBox(HWindow, 'Enter Yes into dialog', 'Error!', mb_Ok);
  47.     SendDlgItemMsg(id_Input, em_SetSel, 0, MAKELONG(32767, 0))
  48.   end;
  49.   CanClose := OkToClose
  50. end;
  51.  
  52.  
  53. { GinputApplication }
  54.  
  55. {- Initialize GinputApplication object's window }
  56. procedure GinputApplication.InitMainWindow;
  57. begin
  58.   MainWindow := New(PGinputWindow, Init(nil, 'Ginput'))
  59. end;
  60.  
  61.  
  62. { GinputWindow }
  63.  
  64. {- Construct GinputWindow object }
  65. constructor GinputWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  66. begin
  67.   TWindow.Init(AParent, ATitle);
  68.   Attr.Menu := LoadMenu(HInstance, PChar(id_Menu));
  69.   Buffer[0] := Chr(0)  { Empty buffer }
  70. end;
  71.  
  72. {- Prompt for input into GinputWindow's Buffer field }
  73. procedure GinputWindow.GetInput(var Msg: TMessage);
  74. begin
  75.   Application^.ExecDialog(New(PCustom,
  76.     Init(@Self, 'Input Dialog', 'Please enter something: ',
  77.     Buffer, Sizeof(Buffer))))
  78. end;
  79.  
  80.  
  81. var
  82.  
  83.   GinputApp: GinputApplication;
  84.  
  85. begin
  86.   GinputApp.Init('GinputApp');
  87.   GinputApp.Run;
  88.   GinputApp.Done
  89. end.
  90.  
  91.  
  92. {--------------------------------------------------------------
  93.   Copyright (c) 1991 by Tom Swan. All rights reserved.
  94.   Revision 1.00    Date: 3/12/1991
  95. ---------------------------------------------------------------}
  96.